const Router = require('koa-router');
const router = new Router();
const {db, QueryTypes, } = require('../../models/db')
const tools = require("../../tools/tool");

router.post('/design/toPy', async ctx => {
    let mod = ctx.request.body.mod;
    let tid = ctx.user.tenantId;
    let list = await db.models[mod].findAll({
        where: {
            tenantId: tid
        },
        attributes: ['id', 'name']
    })
    for (let i = 0; i < list.length; i++) {
        await db.models[mod].update({pinYin: tools.py(list[i].name)},
            {
                where: {
                    id: list[i].id
                }
            })
    }
    return ctx.suc('成功')
})



module.exports = router;
